package com.wuyou.service.impl;

import com.wuyou.dao.ReportDao;
import com.wuyou.pojo.PageBean;
import com.wuyou.pojo.ReQuery;
import com.wuyou.pojo.Report;
import com.wuyou.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 闵洪友
 * @create 2020-09-02 10:51
 */
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    @Resource
    private ReportDao reportDao;

    @Override
    public List<Report> findAll(PageBean pageBean, String pg, ReQuery reQuery) {
        pageBean.setCountSize(countSize(reQuery));
        pageBean.getCountPage();
        //当前页码
        int pgm=0;
        if (pg==null){
            pgm=1;
        }else{
            pgm=new Integer(pg);
        }
        //如果用户输入-1,默认第一页
        if(pgm<1){
            pgm=1;
        }
        //如果用户输入的超过总页码,默认最后一页
        if(pgm>pageBean.getCountPage()){
            pgm=pageBean.getCountPage();
        }
        pageBean.setReQuery(reQuery);
        pageBean.setCurrentPage(pgm);
        return reportDao.findAll(pageBean);
    }

    @Override
    public int countSize(ReQuery reQuery) {
        return reportDao.countSize(reQuery);
    }
}
